/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2022-10-23
 * Time: 19:10
 */


class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Solution {
    public int sum;
    //反中序遍历
    public void reverseInOrder(TreeNode root){
        if(root==null){
            return ;
        }
        reverseInOrder(root.right);
        sum+=root.val;
        root.val=sum;
        reverseInOrder(root.left);
    }
    public TreeNode convertBST(TreeNode root) {
        reverseInOrder(root);
        return root;
    }
}
